package com.flying.carclub.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.flying.carclub.R;
import com.flying.carclub.activity.WebViewActivity;
import com.flying.carclub.utils.UrlUtil;


/**
 * A simple {@link Fragment} subclass.
 * Use the {@link ShowFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class ShowFragment extends Fragment implements View.OnClickListener {

    public ShowFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment ShowFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static ShowFragment newInstance(String param1, String param2) {
        ShowFragment fragment = new ShowFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View contentView = inflater.inflate(R.layout.fragment_show, container, false);
        initView(contentView);
        return contentView;
    }

    private void initView(View view) {
        view.findViewById(R.id.card_oil).setOnClickListener(this);
        view.findViewById(R.id.card_4s).setOnClickListener(this);
        view.findViewById(R.id.card_maintenance_record).setOnClickListener(this);
        view.findViewById(R.id.card_insurance).setOnClickListener(this);
        view.findViewById(R.id.card_sale_car).setOnClickListener(this);
        view.findViewById(R.id.card_shop).setOnClickListener(this);
        view.findViewById(R.id.card_by_stages).setOnClickListener(this);
        view.findViewById(R.id.card_loan).setOnClickListener(this);
        view.findViewById(R.id.card_insurance01).setOnClickListener(this);
        view.findViewById(R.id.card_take_car).setOnClickListener(this);
        view.findViewById(R.id.card_car_show).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int viewId = v.getId();
        Intent intent = new Intent(getActivity(), WebViewActivity.class);
        switch (viewId) {
            case R.id.card_oil:
                intent.putExtra(WebViewActivity.EXTRA_URL, UrlUtil.URL_Oil_Card_Recharge);
                intent.putExtra(WebViewActivity.EXTRA_TITLE, "油卡充值");
                intent.putExtra(WebViewActivity.EXTRA_TITLE_BAR_VISIBLE, false);
                break;
            case R.id.card_4s:
                intent.putExtra(WebViewActivity.EXTRA_URL, UrlUtil.URL_4s_Near);
                intent.putExtra(WebViewActivity.EXTRA_TITLE, "附近4s店");
                intent.putExtra(WebViewActivity.EXTRA_TITLE_BAR_VISIBLE, true);
                break;
            case R.id.card_maintenance_record:
                intent.putExtra(WebViewActivity.EXTRA_URL, UrlUtil.URL_Maintenance_Record);
                intent.putExtra(WebViewActivity.EXTRA_TITLE, "保养记录查询");
                intent.putExtra(WebViewActivity.EXTRA_TITLE_BAR_VISIBLE, true);
                break;
            case R.id.card_insurance:
            case R.id.card_insurance01:
                intent.putExtra(WebViewActivity.EXTRA_URL, UrlUtil.URL_Insurance);
                intent.putExtra(WebViewActivity.EXTRA_TITLE, "汽车保险");
                intent.putExtra(WebViewActivity.EXTRA_TITLE_BAR_VISIBLE, false);
                break;
            case R.id.card_sale_car:
                intent.putExtra(WebViewActivity.EXTRA_URL, UrlUtil.URL_Sale_Car);
                intent.putExtra(WebViewActivity.EXTRA_TITLE, "我要卖车");
                intent.putExtra(WebViewActivity.EXTRA_TITLE_BAR_VISIBLE, true);
                break;
            case R.id.card_shop:
                intent.putExtra(WebViewActivity.EXTRA_URL, UrlUtil.URL_Shop);
                intent.putExtra(WebViewActivity.EXTRA_TITLE, "车品商城");
                intent.putExtra(WebViewActivity.EXTRA_TITLE_BAR_VISIBLE, false);
                break;
            case R.id.card_by_stages:
                intent.putExtra(WebViewActivity.EXTRA_URL, UrlUtil.URL_By_Stages);
                intent.putExtra(WebViewActivity.EXTRA_TITLE, "帮您贷款");
                intent.putExtra(WebViewActivity.EXTRA_TITLE_BAR_VISIBLE, true);
                break;
            case R.id.card_loan:
                intent.putExtra(WebViewActivity.EXTRA_URL, UrlUtil.URL_Loan);
                intent.putExtra(WebViewActivity.EXTRA_TITLE, "车主贷款");
                intent.putExtra(WebViewActivity.EXTRA_TITLE_BAR_VISIBLE, false);
                break;
            case R.id.card_take_car:
                intent.putExtra(WebViewActivity.EXTRA_URL, UrlUtil.URL_Take_Car);
                intent.putExtra(WebViewActivity.EXTRA_TITLE, "拍照识车");
                intent.putExtra(WebViewActivity.EXTRA_TITLE_BAR_VISIBLE, true);
                break;
            case R.id.card_car_show:
                intent.putExtra(WebViewActivity.EXTRA_URL, UrlUtil.URL_Car_Show);
                intent.putExtra(WebViewActivity.EXTRA_TITLE, "汽车车展");
                intent.putExtra(WebViewActivity.EXTRA_TITLE_BAR_VISIBLE, true);
                break;
            default:
                break;
        }
        startActivity(intent);
    }
}
